/**
 * 将对象中的驼峰命名修改为 _
 * @param data
 * @returns
 */
export function dealWithKey(data: any) {
  const obj = {};
  if (Object.keys(data).length === 0) return obj;
  for (const key in data) {
    const newKey = key.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
    obj[newKey] = data[key];
  }
  return obj;
}

/**
 * 将对象中的驼峰命名修改为 _
 * @param data
 * @returns
 */
export function exchangeKey(data: any) {
  const obj = {};
  if (Object.keys(data).length === 0) return obj;
  for (const key in data) {
    const newKey = key.replace(/_(\w)/g, (match, p1) => {
      return p1.toUpperCase();
    });
    obj[newKey] = data[key];
  }
  return obj;
}
